# 转自 https://github.com/changanmoon/UninstallMAU.git


#!/bin/bash
# Copyright 2022-2024 Tiffany Fung

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#    http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Grant sudo
sudo -S id -u
echo "" | awk '{fflush()}'

# Define a universal function to remove file/folder under sudo privileges
function delete() {
    # use "test -e" command to check if a file/folder exists
#    sudo test -e "$1" && sudo rm -rf "$1"
    sudo test -e "$1" && sudo mv -f "$1" ~/.Trash/
    sudo test -e "$1" && sudo mv --reply=yes "$1" ~/.Trash/
}


# clean /Library/Logs
delete /Library/Logs/Multipass

# Remove application support folders
delete /Library/PrivilegedHelperTools/com.microsoft.autoupdate.helper
delete /Library/PrivilegedHelperTools/com.west2online.ClashX.ProxyConfigHelper
delete /Library/PrivilegedHelperTools/com.docker.vmnetd
delete /Library/PrivilegedHelperTools/com.netease.nemu-installer.smjob-helper
delete /Library/PrivilegedHelperTools/com.netease.uumac.helper

# clean /Library/Application\ Support/
delete /Library/Application\ Support/Microsoft/MAU2.0
delete /Library/Application\ Support/Nemu
delete /Library/Application\ Support/Qihoo
delete /Library/Application\ Support/UUBooster
delete /Library/Application\ Support/Unity
delete /Library/Application\ Support/com.canonical.multipass
delete /Library/Application\ Support/赤友NTFS助手

delete ~/Library/Application\ Support/Microsoft\ AutoUpdate
delete ~/Library/Application\ Support/Nemu
delete ~/Library/Application\ Support/Qihoo
delete ~/Library/Application\ Support/UUBooster
delete ~/Library/Application\ Support/Unity
delete ~/Library/Application\ Support/com.canonical.multipass
delete ~/Library/Application\ Support/赤友NTFS助手
delete ~/Library/Application\ Support/HBuilder X
delete ~/Library/Application\ Support/Microsoft Edge
delete ~/Library/Application\ Support/Mozilla
delete ~/Library/Application\ Support/PopCap
delete ~/Library/Application\ Support/VisualVM
delete ~/Library/Application\ Support/arduino-ide
delete ~/Library/Application\ Support/chat2db
delete ~/Library/Application\ Support/com.iBoysoft.NTFS*
delete ~/Library/Application\ Support/com.kugou.mac.Music
delete ~/Library/Application\ Support/com.netease.uumac
delete ~/Library/Application\ Support/com.west2online.ClashX

# Remove preferences
delete /Library/Preferences/com.microsoft.autoupdate2.plist
delete ~/Library/Preferences/com.microsoft.autoupdate2.plist
delete ~/Library/Preferences/com.microsoft.autoupdate.fba.plist
delete ~/Library/Preferences/Unity
delete ~/Library/Preferences/WhatsApp.plist
delete ~/Library/Preferences/cc.arduino.IDE2.plist
delete ~/Library/Preferences/com.Roblox.Roblox.plist
delete ~/Library/Preferences/com.Roblox.StudioBootstrapper.plist
delete ~/Library/Preferences/com.android.Emulator.plist
delete ~/Library/Preferences/com.chat2db.plist
delete ~/Library/Preferences/com.docker.docker.plist
delete ~/Library/Preferences/com.electron.dockerdesktop.plist
delete ~/Library/Preferences/com.iBoysoft.NTFS-Assistant-website-zh.plist
delete ~/Library/Preferences/com.kugou.mac.Music.plist
delete ~/Library/Preferences/com.layabox.LayaAirIDE2.plist
delete ~/Library/Preferences/com.microsoft.VSCode.helper.plist
delete ~/Library/Preferences/com.microsoft.VSCode.plist
delete ~/Library/Preferences/com.microsoft.edgemac.plist
delete ~/Library/Preferences/com.microsoft.shared.plist
delete ~/Library/Preferences/com.mongodb.compass.plist
delete ~/Library/Preferences/com.netease.nemu*
delete ~/Library/Preferences/com.popcap.osx.plantsvszombies.plist
delete ~/Library/Preferences/com.postmanlabs.mac.plist
delete ~/Library/Preferences/com.qihoo.mac360safetray.plist
delete ~/Library/Preferences/com.roblox.*
delete ~/Library/Preferences/com.tencent.QQMusicMac.plist
delete ~/Library/Preferences/com.unity3d*
delete ~/Library/Preferences/com.west2online.ClashX.plist
delete ~/Library/Preferences/com.yonyou.UClient.plist
delete ~/Library/Preferences/dev-sidecar.plist
delete ~/Library/Preferences/group.com.netease.mumu.plist
delete ~/Library/Preferences/io.dcloud.HBuilderX.plist
delete ~/Library/Preferences/multipass
delete ~/Library/Preferences/net.qihoo*
delete ~/Library/Preferences/net.yanue.V2rayU.plist
delete ~/Library/Preferences/org.mozilla.firefox.plist
delete ~/Library/Preferences/unity*
delete ~/Library/Preferences/website.com.360.safeGuardSuite.plist


# Remove containers
delete ~/Library/Group\ Containers/UBF8T346G9.ms
delete ~/Library/Group\ Containers/UBF8T346G9.office
delete ~/Library/Group\ Containers/group.com.docker
delete ~/Library/Group\ Containers/group.com.mac.utility.media.player
delete ~/Library/Group\ Containers/XY6NLV7YTS.com.bytedance.macos.feishu
delete ~/Library/Group\ Containers/W7AR3WMP87.edu.mit.scratch.scratch-desktop
delete ~/Library/Group\ Containers/UBF8T346G9.com.microsoft.oneauth
delete ~/Library/Group\ Containers/5ZSL2CJU2T.com.dingtalk.mac
delete ~/Library/Group\ Containers/XY6NLV7YTS.feishu
delete ~/Library/Group\ Containers/*.com.macpaw.CleanMyMac-mas
delete ~/Library/Group\ Containers/*.sequel-ace
delete ~/Library/Group\ Containers/*.com.cyberlink.powerdirector
delete ~/Library/Group\ Containers/*.com.tencent.WeWorkMac
delete ~/Library/Group\ Containers/*.com.tencent.WeWorkMac.dev
delete ~/Library/Group\ Containers/*.com.tencent.WeWorkMacDebug
delete ~/Library/Group\ Containers/*.com.tencent.WeWorkMacUIDev
delete ~/Library/Group\ Containers/*.WeWorkMac
delete ~/Library/Group\ Containers/*.com.yinxiang.Mac
delete ~/Library/Group\ Containers/*.group.com.dingtalk.mac.tblive
delete ~/Library/Group\ Containers/*bytedance.douyin*

# Remove cache and log files
delete /private/var/db/receipts/com.microsoft.package.Microsoft_AutoUpdate.app.bom
delete /private/var/db/receipts/com.microsoft.package.Microsoft_AutoUpdate.app.plist
delete /private/var/db/receipts/net.qihoo*
delete /private/var/db/receipts/com.unity3d.UnityEditor*
delete /private/var/db/receipts/com.trendmicro*
delete /private/var/db/receipts/com.tencent.WeWorkMac*
delete /private/var/db/receipts/com.tencent.LemonLite*
delete /private/var/db/receipts/com.sequel-ace.sequel-ace*
delete /private/var/db/receipts/com.nara.Advanced-SystemCleaner*
delete /private/var/db/receipts/com.microsoft.edgemac*
delete /private/var/db/receipts/com.macpaw.CleanMyMac-mas*
delete /private/var/db/receipts/com.mac.utility.*
delete /private/var/db/receipts/com.mac.utility.mirror.samsung.bom
delete /private/var/db/receipts/com.mac.utility.mirror.samsung.plist
delete /private/var/db/receipts/com.kugou.mac*
delete /private/var/db/receipts/com.iboysoft*
delete /private/var/db/receipts/com.extension.doubao*
delete /private/var/db/receipts/com.cyberlink*
delete /private/var/db/receipts/com.canonical.multipass*
delete /private/var/db/receipts/com.bytedance.douyin.desktop.plist
delete /private/var/db/receipts/com.bytedance.macos.feishu*
delete /private/var/db/receipts/*.com.dingtalk.mac*
delete /private/var/db/receipts/com.youku.mac.bom
delete /private/var/db/receipts/com.youku.mac.plist
delete /Library/Logs/Microsoft
delete ~/Library/Caches/com.microsoft.autoupdate.fba
delete ~/Library/Caches/com.microsoft.autoupdate2
delete ~/Library/Caches/HBuilder X
delete ~/Library/Caches/Microsoft
delete ~/Library/Caches/Microsoft Edge
delete ~/Library/Caches/com.kugou.mac.Music
delete ~/Library/Caches/com.microsoft.edgemac
delete ~/Library/Caches/com.netease.uumac
delete ~/Library/Caches/net.qihoo.mac360safe
delete ~/Library/Caches/net.qihoo.mac360safetray

delete ~/Library/HTTPStorages/com.microsoft.autoupdate2

# Remove startup items
delete /Library/LaunchDaemons/com.microsoft.autoupdate.helper.plist
delete /Library/LaunchDaemons/com.microsoft.update.agent.plist
delete /Library/LaunchDaemons/com.canonical.multipassd.plist
delete /Library/LaunchDaemons/com.docker.vmnetd.plist
delete /Library/LaunchDaemons/com.iBoysoft.ntfshelperd.plist
delete /Library/LaunchDaemons/com.netease.nemu-installer.smjob-helper.plist
delete /Library/LaunchDaemons/com.netease.nemu.startup.plist
delete /Library/LaunchDaemons/com.netease.uumac.helper.plist
delete /Library/LaunchDaemons/com.west2online.ClashX.ProxyConfigHelper.plist
delete /Library/LaunchAgents/com.microsoft.update.agent.plist

# Remove Microsoft Office Licensing helper
delete /Library/LaunchDaemons/com.microsoft.office.licensingV2.helper.plist

# Remove OneDrive SyncReporter
delete /Library/LaunchAgents/com.microsoft.SyncReporter.plist

# Remove OneDrive StandaloneUpdater and its daemon
delete /Library/LaunchAgents/com.microsoft.OneDriveStandaloneUpdater.plist
delete /Library/LaunchDaemons/com.microsoft.OneDriveStandaloneUpdaterDaemon.plist
delete /Library/LaunchDaemons/com.microsoft.OneDriveUpdaterDaemon.plist

# Ending
sudo killall Finder; killall Dock
exit
